<?php
//    file_put_contents('/var/www/html/pf_system/liuqi111.txt',time(),FILE_APPEND);
    $mysql_server="47.96.41.168";
    $mysql_username="qianhai";
    $mysql_password="qian960hai^";
    $mysql_database="paifu_system";

    $conn = mysql_connect($mysql_server,$mysql_username,$mysql_password);

    if(!$conn){
        file_put_contents('/var/www/html/pf_system/1111.txt','mysql connect fail at '.time()."\r\n",FILE_APPEND);
    }
    mysql_select_db($mysql_database,$conn);
    mysql_query("set names 'utf8'");


    $etime = time()-600000;
    $senvDay = 7*3600*24;
    $sql = "SELECT id,send_at FROM pf_jolly_order WHERE order_status = 1 AND send_at < $etime";
    $result=mysql_query($sql);

    $new_row = [];

    if($result){
        while($r = mysql_fetch_assoc($result)){
            if(time() - $r['send_at'] >= $senvDay){
                $new_row[] = $r;
            }
        }
    }

    if($new_row){
        foreach($new_row as $k=>$v){
            $now = time();
            $id = intval($v['id']);
            $sq = "UPDATE pf_jolly_order SET is_auto_complete = 1,order_status = 2,complete_at = $now WHERE id = $id";
            $res = mysql_query($sq);
        }
    }
    mysql_free_result($result);
    mysql_close($conn);